package org.example.route.mapper;

import org.apache.ibatis.annotations.*;
import org.example.route.model.dto.PriceDTO;
import org.example.route.model.pojo.Price;

import java.util.List;

@Mapper
public interface PriceMapper {


    @Insert("insert into price (go_id1, go_id2, the_price, grade, count, last_count, byuser,disabled) VALUES " +
            "(#{goId1},#{goId2},#{thePrice},#{grade},#{count},#{count},#{byUser},false)")
    void add(PriceDTO priceDTO);

    List<Price> getByDoubleIdsAndGrade(Long goId1, Long goId2, Long grade);

    @Update("update price set last_count = last_count - 1 where id = #{priceId}")
    void bePayed(Long priceId);

    @Select("select * from price where id = #{priceId}")
    Price getById(Long priceId);

    @Update("update price set last_count = last_count + 1 where id = #{priceId}")
    void beReleased(Long priceId);


    @Select("select * from price where go_id1 = #{goId} or go_id2 = #{goId} ")
    List<Price> getByGoId(Long goId);


    void update(PriceDTO priceDTO);

    @Delete("delete from price where id = #{id}")
    void delete(Long id);
}
